Ext.define("BioGene.view.AbstractView", {
	extend: "Ext.Panel",
	alias: "widget.abstractview",
	config: {
		id : 'abstractPanel',
		layout: 'fit',
		styleHtmlContent: true,
		scrollable: true,
		tpl: new Ext.XTemplate(
			'{journal}<br /><br />',
			'<b>{title}</b><br /><br />',
			'<tpl if="authors != \'\'">',
				'{authors}<br /><br />',
			'</tpl>',
			'<tpl if="affiliation != \'\'">',
				'{affiliation}<br /><br />',
			'</tpl>',
			'<tpl if="abstract != \'\'">',
				'{abstract}<br /><br />',
			'</tpl>',
			'<tpl for="ids">',
				'{.}<br />',
			'</tpl>'
		)
	},
    readIntoView: function (pubmed_id) {
    	//Function Sets link on pubmed button
    	BioGene.views.abstractView.pubButton.setHandler(function(){window.open('http://www.ncbi.nlm.nih.gov/m/pubmed/'+pubmed_id)});
    },
    
    initialize: function () {

		this.callParent(arguments);

        // Close Button 
        var closeButton = new Ext.Button({
            text: 'Close',
            ui: 'normal',
            id: 'abstractCloseButton',
            handler: this.onCloseTap
        });
        
        // Pubmed Link Button
        var pubButton = new Ext.Button({
            text: 'PubMed',
            ui: 'normal',
            id: 'pubmedLink',
            handler: function(){
            	window.open('http://www.google.com');
            }
        });

		// Setting up the toolbar for the view
        var topToolbar = new Ext.Toolbar({
            title: 'Abstract',
            docked: 'top',
            items: [
            	closeButton,
            	{ xtype: 'spacer' },
            	pubButton
            ]
        });

        this.add([topToolbar]);

    },

	// Close button function
    onCloseTap: function () {
        this.fireEvent("geneReturn", this);
    }
    
});